﻿using System;
using Automator.Tasks.Core;
using Automator.Tasks.Windows;
using System.Windows;
using System.Windows.Media.Imaging;

namespace Automator.Tasks
{
    /// <summary>
    /// Class for storing any text information that doesn't affect script execution.
    /// Some guidelines for the following Tasks, for example.
    /// Defined attributes:
    /// Text: comment itself
    /// </summary>
    public class CommentTask: Task
    {
        public CommentTask()
            : base()
        {
            this.Title = "Comment";
            this.Description = "Text information";
            this.TaskImage = new BitmapImage(new Uri("/Automator.Tasks;component/Resources/comment.png", UriKind.Relative));
            this.IsActive = false;
            this.IsEnabled = false;
            this.CanHaveDependencies = false;

            this.Attributes.Add(new TaskAttributeDefinition() { Key = "Text", Value = String.Empty });
        }

        public CommentTask(string comment)
            : this()
        {
            this.Attributes["Text"].Value = comment;
        }

        public override string CommandText
        {
            get
            {
                return this.Attributes["Text"].Value.ToString().Trim();
            }
            set { base.CommandText = value; }
        }

        public override bool EditTask()
        {
            base.EditTask();
            CommentTaskEditWindow window = new CommentTaskEditWindow();
            window.Owner = Application.Current.MainWindow;
            window.Title = String.Format("Edit {0} Task", this.Title);
            //performing binding to the header
            window.header.ContentPanel.DataContext = this;

            window.edtText.Text = this.Attributes["Text"].Value.ToString();
            window.footer.BtnOK.Click += delegate { window.DialogResult = true; };

            if (window.ShowDialog() == true)
            {
                this.Attributes["Text"].Value = window.edtText.Text.Trim();
                this.CommandText = String.Empty;
                return true;
            }
            else
                return false;
        }
    }
}
